﻿using System.Threading.Tasks;
using SmartCity.Shared;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;

namespace CommonManagement
{
    /// <summary>
    /// 积分管理类
    /// </summary>
    public class ScoreManager : DomainService
    {
        private readonly IRepository<Score, int> _scoreRepository;

        public ScoreManager(
            IRepository<Score, int> scoreRepository)
        {
            _scoreRepository = scoreRepository;
        }

        public async Task<Score> CreateAsync(
            int userId,
            ScoreEvent @event,
            int score,
            ScoreChangeType type)
        {
            return await _scoreRepository.InsertAsync(
                new Score(
                    userId,
                    @event,
                    score,
                    type
                )
            );
        }
    }
}